<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script type="text/javascript" src="../js/vue.js"></script>
    <script type="text/javascript" src="../js/axios.min.js"></script>
    <script type="text/javascript" src="../js/vue-router.js"></script>
    <script type="text/javascript" src="../js/jquery.min.js"></script>
    <script type="text/javascript" src="../js/bootstrap.min.js"></script>
    <link type="text/css" rel="stylesheet" href="../css/bootstrap.min.css">
    <link type="text/css" rel="stylesheet" href="../css/animate.css">
</head>

<body>
    <div class="container">
        <div id="app">
            <!-- 通过v-bind把需要传递给子组件的数据以属性绑定的形式传递到子组件内部 -->
            <com1 :msg="message"></com1>
        </div>

        <div id="app2">
            <com2 @func="show"></com2>
        </div>


        <template id="component1">
            <div>
                <h2>我是子组件h2的数据</h2>
                <button class="btn btn-primary" @click="showChild">我是子组件中的按钮，点击我触发父组件传递过来的func方法</button>
            </div>
        </template>
    </div>
    <script>
        var vm = new Vue({
            el: '#app',
            data: {
                message: '父组件中的数据'
            },
            methods: {},
            components: {
                com1: {
                    // 子组件中通过props来定义接受父组件传递过来的参数
                    props: ['msg'],
                    template: `<h1>这是一个私有的子组件h1{{msg}}</h1>`
                }
            }
        });


        var com2 = {
            template: '#component1',
            methods: {
                showChild() {
                    // emit英文原意为触发，调用，发射的意思。
                    this.$emit('func', 123)
                }
            }
        }

        var app2 = new Vue({
            el: '#app2',
            data: {},
            methods: {
                show(data) {
                    alert("hahahahahahahaha---" + data);
                }
            },
            components: {
                com2
            }
        });
    </script>
</body>

</html>